﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace haptic.src.engine.animation
{
    [Serializable]
    public class Sprite
    {
        #region Constructors
        public Sprite(){}
        public Sprite(string sFilePath)
        {
            m_sFilePath = sFilePath;
        }
        #endregion

        #region Load
        public void Load(ContentManager oContent)
        {
            if (m_sFilePath != null)
            {
                m_oTexture = oContent.Load<Texture2D>(m_sFilePath);
            }
         
            if (m_uiFrameCount == 1)
            {
                if (m_oTexture != null)
                {
                    m_uiFrameWidth = (uint)m_oTexture.Width;
                    m_uiFrameHeight = (uint)m_oTexture.Height;
                }
                m_fFrameDelay = 0.0f;
            }
            else
            {
                m_uiFrameCount = 1;
                if (m_oTexture != null)
                {
                    m_uiFrameHeight = (uint)m_oTexture.Height;
                    m_uiFrameCount = (uint)m_oTexture.Width / m_uiFrameWidth;
                }
                m_fFrameDelay = m_fTotalDuration / (float)m_uiFrameCount;
            }
        }
        #endregion

        #region Attributes
        [XmlAttribute("file-path")]
        public string m_sFilePath;
        Texture2D m_oTexture;
        [XmlIgnore]
        public Texture2D oTexture { get { return m_oTexture; } }
        private float m_fFrameDelay;
        public float fFrameDelay { get { return m_fFrameDelay; } }
        [XmlAttribute("frame-width")]
        public uint m_uiFrameWidth = 10;
        [XmlIgnore]
        public uint m_uiFrameHeight;
        [XmlIgnore]
        public uint m_uiFrameCount = 0;
        private float m_fTotalDuration = 0.0f;
        [XmlAttribute("duration")]
        public float fTotalDuration { get { return m_fTotalDuration; } set { m_fTotalDuration = value; } }
        #endregion
    }
}
